package 牛客网_N.电话号码分身_N4;


import java.util.Scanner;

/**
 * 
 * @author x
 * @summary 继MIUI8推出手机分身功能之后，MIUI9计划推出一个电话号码分身的
 * 功能：首先将电话号码中的每个数字加上8取个位，然后使用对应的大写字母代替 （
 * "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", 
 * "EIGHT", "NINE"）， 然后随机打乱这些字母，所生成的字符串即为电话号码对应的分身。
 * 
 * 第一行是一个整数T（1 ≤ T ≤ 100)表示测试样例数；接下来T行，每行给定一个分身后的
 * 电话号码的分身（长度在3到10000之间）。
 * 4
EIGHT
ZEROTWOONE
OHWETENRTEO
OHEWTIEGTHENRTEO
 * 
 * 输出T行，分别对应输入中每行字符串对应的分身前的最小电话号码（允许前导0）。
 * 0
234
345
0345
 * 
 */
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i = 0; i < n; i++){
			getReal(in.next());
		}
		in.close();
	}

	private static void getReal(String str) {
		StringBuffer sb = new StringBuffer(str.trim());
		int[] n = new int[10];
		while(sb.toString().contains("Z")){
			sb.deleteCharAt(sb.indexOf("Z"));
			sb.deleteCharAt(sb.indexOf("E"));
			sb.deleteCharAt(sb.indexOf("R"));
			sb.deleteCharAt(sb.indexOf("O"));
			n[2]++;
		}
		while(sb.toString().contains("W")){
			sb.deleteCharAt(sb.indexOf("T"));
			sb.deleteCharAt(sb.indexOf("W"));
			sb.deleteCharAt(sb.indexOf("O"));
			n[4]++;
		}
		while(sb.toString().contains("U")){
			sb.deleteCharAt(sb.indexOf("F"));
			sb.deleteCharAt(sb.indexOf("O"));
			sb.deleteCharAt(sb.indexOf("U"));
			sb.deleteCharAt(sb.indexOf("R"));
			n[6]++;
		}
		while(sb.toString().contains("X")){
			sb.deleteCharAt(sb.indexOf("S"));
			sb.deleteCharAt(sb.indexOf("I"));
			sb.deleteCharAt(sb.indexOf("X"));
			n[8]++;
		}
		while(sb.toString().contains("S")){
			sb.deleteCharAt(sb.indexOf("S"));
			sb.deleteCharAt(sb.indexOf("E"));
			sb.deleteCharAt(sb.indexOf("V"));
			sb.deleteCharAt(sb.indexOf("E"));
			sb.deleteCharAt(sb.indexOf("N"));
			n[9]++;
		}
		while(sb.toString().contains("G")){
			sb.deleteCharAt(sb.indexOf("E"));
			sb.deleteCharAt(sb.indexOf("I"));
			sb.deleteCharAt(sb.indexOf("G"));
			sb.deleteCharAt(sb.indexOf("H"));
			sb.deleteCharAt(sb.indexOf("T"));
			n[0]++;
		}
		while(sb.toString().contains("O")){
			sb.deleteCharAt(sb.indexOf("O"));
			sb.deleteCharAt(sb.indexOf("N"));
			sb.deleteCharAt(sb.indexOf("E"));
			n[3]++;
		}
		while(sb.toString().contains("V")){
			sb.deleteCharAt(sb.indexOf("F"));
			sb.deleteCharAt(sb.indexOf("I"));
			sb.deleteCharAt(sb.indexOf("V"));
			sb.deleteCharAt(sb.indexOf("E"));
			n[7]++;
		}
		while(sb.toString().contains("T")){
			sb.deleteCharAt(sb.indexOf("T"));
			sb.deleteCharAt(sb.indexOf("H"));
			sb.deleteCharAt(sb.indexOf("R"));
			sb.deleteCharAt(sb.indexOf("E"));
			sb.deleteCharAt(sb.indexOf("E"));
			n[5]++;
		}
		while(sb.toString().contains("I")){
			sb.deleteCharAt(sb.indexOf("N"));
			sb.deleteCharAt(sb.indexOf("I"));
			sb.deleteCharAt(sb.indexOf("N"));
			sb.deleteCharAt(sb.indexOf("E"));
			n[1]++;
		}
		
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < n[i]; j++){
				System.out.print(i);
            }
		}
		System.out.println();
	}
}
